package Util;

import java.util.ArrayList;

import com.vargas.studypartner.R;

import Domain.Deck;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * List adapter for displaying deck items.
 * */
public class DeckListAdapter extends ArrayAdapter<Deck>{
	
	private Context _Context;
	private int _ResourceID;
	
	/**
	 * Default constructor. Sets the member variables.
	 * @param context 	The application context instance.{@link Context}
	 * @param res			The resource ID of the list view element.
	 * @param list		The array list of decks to display.{@link ArrayList}
	 * */
	public DeckListAdapter(Context context, int res, ArrayList<Deck> list) {
		super(context, res, list);
		_Context = context;
		_ResourceID = res;
	}
	
	/**
	 * Gets the base view and processes it to add deck information to view elements
	 * and make any customizations via {@link LayoutInflater}.
	 * @param	position	The position in the list of the current deck.
	 * @param	convertView	The view to be processed.{@link View}
	 * @param	parent		The top level view element.{@link ViewGroup}
	 * @return 	The processed view. {@link View}
	 * */
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		View row;
		 
		if (null == convertView) {
			LayoutInflater inflater = ((Activity)_Context).getLayoutInflater();
			row = inflater.inflate(_ResourceID, null);
		} else {
			row = convertView;
		}
 
		TextView tv = (TextView) row.findViewById(R.id.text1);  
		tv.setText(getItem(position).getName());
 
		return row;
    }
}
